package com.j180.dao.store;

import com.j180.bean.Store;
import com.j180.bean.StoreCount;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IStoreDao {
    /**
     * 平台管理员查询门店所有信息
     * @return  查询信息
     */
    @Select("select sto.st_id\n" +
            "             ,sto.st_name\n" +
            "             ,sto.st_licenseNum\n" +
            "             ,sto.st_licensePic\n" +
            "             ,sto.st_address\n" +
            "             ,sto.st_location\n" +
            "             ,sto.st_city\n" +
            "             ,sto.st_corporation\n" +
            "             ,sto.st_telNum\n" +
            "             ,sto.st_photo\n" +
            "             ,sto.st_feature\n" +
            "             ,sto.st_vipLevel\n" +
            "             ,sto.st_commissionRate\n" +
            "             ,sto.st_clerkAttri\n" +
            "             ,us.u_id\n" +
            "              from\n" +
            "              t_store as sto LEFT JOIN t_user as us\n" +
            "              on sto.st_u_id=us.u_id")
    @ResultMap("storeResult.StoreUserMap")
    public List<Store> getAllStoreInfo();


    /**
     * 平台管理员根据id查询门店所有信息
     * @return   查询信息
     */
    @Select("select st_id as id" +
            ",st_name as name" +
            ",st_licenseNum as licenseNum" +
            ",st_licensePic as licensePic" +
            ",st_address as address" +
            ",st_location as location" +
            ",st_city as city" +
            ",st_corporation corporation" +
            ",st_telNum as telNum" +
            ",st_photo as photo" +
            ",st_feature as feature" +
            ",st_vipLevel as vipLevel" +
            ",st_commissionRate as commissionRate" +
            ",st_clerkAttri as clerkAttri " +
            "from t_store where st_id =#{id}")
    public Store getStoreDetailInfoById(@Param("id") int id);

    /**
     * 根据门店ID连表查询所有门店的详细信息（门店管理员）
     * @return   查询结果
     */
    @Select("select sto.st_id\n" +
            "\t\t\t,sto.st_name\n" +
            "\t\t\t,sto.st_licenseNum\n" +
            "\t\t\t,sto.st_licensePic\n" +
            "\t\t\t,sto.st_address\n" +
            "\t\t\t,sto.st_location\n" +
            "\t\t\t,sto.st_city\t\n" +
            "\t\t\t,sto.st_corporation\n" +
            "\t\t\t,sto.st_telNum \n" +
            "\t\t\t,sto.st_photo\n" +
            "\t\t\t,sto.st_feature \n" +
            "\t\t\t,sto.st_vipLevel\n" +
            "\t\t\t,sto.st_commissionRate\n" +
            "\t\t\t,sto.st_clerkAttri\n" +
            "\t\t\t,us.u_id\n" +
            "\t\t\t,us.u_name\n" +
            "\t\t\t,us.u_email\n" +
            "\t\t\t,us.u_identity\n" +
            "\t\t\t,us.u_telNum\n" +
            "\t\t\t,us.u_loginName\n" +
            "\t\t\t,us.u_password\n" +
            "\t\t\t,us.u_state\n" +
            "\t\t\t,sug.sug_id\n" +
            "\t\t\t,sug.sug_name\n" +
            "\t\t\t,sug.sug_type\n" +
            "\t\t\t,sug.sug_material\n" +
            "\t\t\t,sug.sug_applicable\n" +
            "\t\t\t,sug.sug_exclusive\n" +
            "\t\t\t,sug.sug_packingSize\n" +
            "\t\t\t,sug.sug_flavor\n" +
            "\t\t\t,sug.sug_function\n" +
            "\t\t\t,sug.sug_origin\n" +
            "\t\t\t,sug.sug_dateOfPro\n" +
            "\t\t\t,sug.sug_expDate\n" +
            "\t\t\t,sug.sug_supId\n" +
            "\t\t\t,sug.sug_explain\n" +
            "\t\t\t,sug.sug_price\n" +
            "\t\t\t,sug.sug_pic\n" +
            "\t\t\t,ser.se_id\n" +
            "\t\t\t,ser.se_name\n" +
            "\t\t\t,ser.se_type\n" +
            "\t\t\t,ser.se_schedule\n" +
            "\t\t\t,ser.se_applicable\n" +
            "\t\t\t,ser.se_serviceSpec\n" +
            "\t\t\t,ser.se_spendTime\n" +
            "\t\t\t,ser.se_clerkLevel\n" +
            "\t\t\t,ser.se_price\n" +
            "\t\t\t,stg.stg_id\n" +
            "\t\t\t,stg.stg_name\n" +
            "\t\t\t,stg.stg_type\n" +
            "\t\t\t,stg.stg_material\n" +
            "\t\t\t,stg.stg_applicable\n" +
            "\t\t\t,stg.stg_exclusive\n" +
            "\t\t\t,stg.stg_packingSize\n" +
            "\t\t\t,stg.stg_flavor\n" +
            "\t\t\t,stg.stg_function\n" +
            "\t\t\t,stg.stg_origin\n" +
            "\t\t\t,stg.stg_dateOfPro\n" +
            "\t\t\t,stg.stg_expDate\n" +
            "\t\t\t,stg.stg_explain\n" +
            "\t\t\t,stg.stg_price\n" +
            "\t\t\t,stg.stg_pic\n" +
            "\t\t\t,com.c_id\n" +
            "\t\t\t,com.c_time\n" +
            "\t\t\t,com.c_score\n" +
            "\t\t\t,com.c_content\n" +
            "\t\t\t,com.c_pic\n" +
            "\t\t\t,com.c_type \n" +
            "\t\t\t,ord.o_id\n" +
            "\t\t\t,ord.o_money from \n" +
            "\t\t\tt_store as sto LEFT JOIN t_user as us \n" +
            "\t\t\ton sto.st_u_id=us.u_id LEFT JOIN t_comment as com \n" +
            "\t\t\ton com.c_st_id = sto.st_id LEFT JOIN t_stogoods as stg \n" +
            "\t\t\ton stg.stg_st_id = sto.st_id left join t_supgoods as sug \n" +
            "\t\t\ton sug.sug_st_id LEFT JOIN t_service as ser \n" +
            "\t\t\ton ser.se_st_id = sto.st_id left join t_order as ord\n" +
            "\t\t\ton ord.o_st_id = sto.st_id where sto.st_id =#{id}")
    @ResultMap("storeResult.StoreMap")
    public List<Store> getAllStoreInfoForConnect(@Param("id") int id);

    /**
     * 添加新门店
     * @param store 传入商店实体
     */
    @Insert("insert into t_store values(null" +
            ",#{name}" +
            ",#{licenseNum}" +
            ",#{licensePic}" +
            ",#{address}" +
            ",#{location}" +
            ",#{city}" +
            ",#{corporation}" +
            ",#{telNum}" +
            ",#{photo}" +
            ",#{feature}" +
            ",#{vipLevel}" +
            ",#{commissionRate}" +
            ",#{clerkAttri}" +
            ",#{user.id})")
    public int addStore(Store store);

    /**
     * 删除门店
     * @param id  门店ID
     */
    @Delete("delete from t_store where st_id = #{id}")
    public int delStore(@Param("id")int id);


    /**
     *  更新修改门店信息
     * @param store 传入门店实体
     */
    @Update("update t_store set st_name=#{name}" +
            ",st_licenseNum=#{licenseNum}" +
            ",st_licensePic=#{licensePic}" +
            ",st_address=#{address}" +
            ",st_location=#{location}" +
            ",st_city=#{city}" +
            ",st_corporation=#{corporation}" +
            ",st_telNum=#{telNum}" +
            ",st_photo=#{photo}" +
            ",st_feature=#{feature}" +
            ",st_vipLevel=#{vipLevel}" +
            ",st_commissionRate=#{commissionRate}" +
            ",st_clerkAttri=#{clerkAttri}" +
            ",st_u_id=#{user.id}" +
            "  where st_id=#{id}")
    public int EditStore(Store store);

    /**
     * 根据门店名称查询门店信息
     * @param name 门店名称
     * @return 查询结果
     */
    @Select("select st_id as id,st_name as name,st_licenseNum as licenseNum ,st_licensePic as licensePic,st_address as address,st_location as location,st_city as city,st_corporation as corporation,st_telNum as telNum,st_photo as photo,st_feature as feature,st_vipLevel as vipLevel,st_commissionRate as commissionRate,st_clerkAttri as clerkAttri  from t_store where st_name like '%${name}%' ")
    public List<Store> getStoreDetailInfoByStoreName(@Param("name") String name);

    /**
     * 门店管理员根据门店ID和开始时间到结束时间查看销售数量
     * @param id 门店ID
     * @return 查询结果集
     */
    @Select("select stg_name as name, stg_price as price, d_gNum as num, o_createTime as createTime from t_stogoods as stg left join t_detail as det on d_stg_id = stg_id left join t_order as ord on o_id = d_o_id left join t_store as sto on o_st_id = st_id where st_id = #{id}")
    public List<StoreCount> getStoreSalesVolumeForDate(@Param("id")int id);

}
